package cn.wolfcode.trip.base.domain;

import cn.wolfcode.trip.base.util.JSONUtil;
import lombok.Getter;
import lombok.Setter;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * 攻略文章
 */
@Setter
@Getter
public class StrategyDetail extends BaseDomain{
    public static final int STATE_COMMON = 0;//草稿
    public static final int STATE_RELEASE = 1;//发布
    public static final int STATE_DISABLE = -1;//禁用
    //标题
    private String title;
    //创建时间
    private Date createTime;
    //发布时间
    private Date releaseTime;
    //序号
    private Integer sequence;
    //所属攻略目录
    private StrategyCatalog strategyCatalog;
    //关联攻略内容
    private StrategyContent strategyContent;
    //封面
    private String coverUrl;
    //状态
    private Integer state;

    public String getStateName(){
        String msg = "草稿";
        if (STATE_RELEASE == state){
            msg = "发布";
        }else if (STATE_DISABLE == state){
            msg = "禁用";
        }
        return msg;
    }
    public String getJson(){
        Map<String,Object> map = new HashMap<>();
        map.put("id",id);
        map.put("title",title);
        map.put("releaseTime",releaseTime);
        map.put("sequence",sequence);
        map.put("coverUrl",coverUrl);
        map.put("state",state);
        if (strategyCatalog!=null){
            map.put("strategyCatalogId",strategyCatalog.getId());
            map.put("strategyCatalogName",strategyCatalog.getName());
            if (strategyCatalog.getStrategy() != null) {
                map.put("strategyId",strategyCatalog.getStrategy().getId());
            }
        }
        if (strategyContent != null) {
            map.put("content",strategyContent.getContent());
        }
        return JSONUtil.toJSONString(map);
    }
}